<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@ page import="com.test.util.*"%>
<%@ page import="java.util.*"%>
<%@ page import="com.test.Constants"%>
<%@page import="com.test.clyq.service.VisitLogsService"%>
<%@page import="com.test.util2.TimeStamp"%>
<%@page import="com.test.clyq.entity.VisitLogsCountResult"%>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<script language="JavaScript" src="/static/js/chartsJs/FusionCharts.js"></script>
		<title>访问流量统计图</title>
	</head>
	<% 
	System.out.println("==============================================================================================");
	Map<String,Long> map_init = new HashMap<String,Long>();
	StringBuilder mmXml = new StringBuilder();
	String startTime = request.getParameter("startTime");
	String endTime = request.getParameter("endTime");
	String searchType = request.getParameter("searchType");
	String title=request.getParameter("lId");
	System.out.println(searchType);
	
	
	VisitLogsService visitLogsService = (VisitLogsService) Constants.ctx.getBean("visitLogsService");

	
	
	if(startTime==null || "".equals(startTime)){
		startTime = DateUtils.getTime(-7)+"000000";
	}else{
		startTime=startTime.replaceAll("-", "")+"000000";
	}

	if(endTime==null || "".equals(endTime)){
		endTime=TimeStamp.getTime(TimeStamp.YYYYMMDD)+"000000";
	}else{
		endTime=endTime.replaceAll("-", "")+"000000";
	}
	
	mmXml.append("<chart bgAlpha='10,10' bgAngle='270' bgColor='FFFFFF,CC3300' chartRightMargin='35' numvdivlines='5' ");
	mmXml.append("labelStep='2' shadowAlpha='40' alternateHGridColor='CC3300' alternateHGridAlpha='5' showAlternateHGridColor='1' ");
	mmXml.append("divLineIsDashed='1' divLineColor='CC3300' divLineAlpha='20' anchorRadius='2' formatNumberScale='0' showValues='0' ");
	mmXml.append("lineThickness='1' subcaption='(从 "+startTime.substring(0,8)+" 到 "+endTime.substring(0,8)+")' caption='"+("phone".equals(searchType)?"手机":"内容")+" 访问量/天'> ");
	
	int day_num=DateUtils.compareTime(DateUtils.toLong(startTime),DateUtils.toLong(endTime));
	long curr=DateUtils.toLong(startTime);
	mmXml.append("<categories> ");
	System.out.println(day_num);
	for(int i=0;i<(day_num-1);i++){
		if(i!=0){
			curr=curr+(24*60*60*1000);
		}
		
		map_init.put(DateUtils.longToDateString(curr,"yyyyMMdd"),0l);
		mmXml.append("<category label='");
		mmXml.append(DateUtils.longToDateString(curr,"yyyyMMdd"));
		mmXml.append("'/> ");
	}
	mmXml.append("</categories> ");
	if("phone".equals(searchType)){
		searchType="phone_image";
	}else{
		searchType="title_image";
	}
	List<VisitLogsCountResult> daylist=visitLogsService.getVisitLogByTime(startTime,endTime,searchType,title);
	if(daylist!=null && !daylist.isEmpty()){
		for(VisitLogsCountResult obj : daylist){
			map_init.put(obj.getCategoryName(),obj.getCount());
			System.out.println(obj.getCategoryName()+" ========= "+map_init.get(obj.getCategoryName()));
		}
	}
	
	mmXml.append("<dataset anchorBgColor='1D8BD1' anchorBorderColor='1D8BD1' color='1D8BD1'> ");
	for (Map.Entry<String, Long> entry : map_init.entrySet()) {
	System.out.println(entry.getKey().toString()+" -------- "+entry.getValue().toString());
		mmXml.append("<set value='");
		mmXml.append(entry.getValue().toString());
		mmXml.append("'/>");
	}
	mmXml.append("</dataset>");
	mmXml.append("<styles> ");
	mmXml.append("<definition> ");
	mmXml.append("<style size='12' type='font' name='CaptionFont'/> ");
	mmXml.append("</definition>");
	mmXml.append("<application> ");
	mmXml.append("<apply styles='CaptionFont' toObject='CAPTION'/> ");
	mmXml.append("<apply styles='CaptionFont' toObject='SUBCAPTION'/> ");
	mmXml.append("</application> ");
	mmXml.append("</styles> ");
	mmXml.append("</chart>");
	
	
	%>
	<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" style="font-size: 13px;">
		<div id="chartdiv" align="center">
		<!-- setDateXml -->
		</div>
		<script type="text/javascript">
		   var chart = new FusionCharts("/static/chartsSwf/MSLine.swf", "ChartId", "1024", "400", "0", "0");
		   chart.setDataXML("<%=mmXml.toString() %>");		   
		   chart.render("chartdiv");
		</script>
	</body>
</html>
